/*
 * @lc app=leetcode.cn id=477 lang=cpp
 *
 * [477] 汉明距离总和
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
    

public:
    int totalHammingDistance(vector<int> &nums)
    {
        int ans = 0;
        array<int, 32>  arr = {0};
        for(auto n : nums)
        {
            for(int i = 0; i < 32; i++)
            {
                arr[i] += (n >> i) & 0x1;
            }
        }

        for(auto n : arr)
        {
            ans += (nums.size() - n) * n;
        }
        
        return ans;
    }
};
// @lc code=end
